layui.use(['form','layer','jquery','laypage'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		$ = layui.jquery;

    //全选
	form.on('checkbox(allChoose)', function(data){
		var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"])');
		child.each(function(index, item){
			item.checked = data.elem.checked;
		});
		form.render('checkbox');
	});

	//通过判断文章是否全部选中来确定全选按钮是否选中
	form.on("checkbox(choose)",function(data){
		var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"])');
		var childChecked = $(data.elem).parents('table').find('tbody input[type="checkbox"]:not([name="show"]):checked')
		if(childChecked.length == child.length){
			$(data.elem).parents('table').find('thead input#allChoose').get(0).checked = true;
		}else{
			$(data.elem).parents('table').find('thead input#allChoose').get(0).checked = false;
		}
		form.render('checkbox');
	})
// 审核开关
    form.on('switch(isOn)', function(data){
        var id = $(this).attr('data-id');
        var uid = $(this).attr('data-uid');
        var money = $(this).attr('data-money');
        var paytime = $(this).attr('data-paytime');
        var orig = $(this).prop('checked');
        var that = $(this);
        if (orig) {
            var status = 1;
        } else {
            var status = 3;
        }
        var index = layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
        //询问框
        layer.confirm('此条记录涉及到用户的资金，确定后不可再做变更！您是否确定？', {
            btn: ['确认','取消'] //按钮
        }, function(){
        	$.ajax({
            url: '/actVerfEdit',
            type: 'GET',
            dataType: 'json',
            timeout: 2000,
            data: {id: id, status: status,uid: uid,money: money,paytime: paytime},
            complete: function(){
                layer.close(index);
            },
            error: function(){
                that.prop('checked', orig);
                layer.alert('参数错误', {icon: 2}, function(index){
                    layer.close(index);
                });
            },
            success: function(res){
                if (res.status != 0) {
                    that.prop('checked', orig);
                    layer.msg(res.msg);
                } else {
                    layer.msg("已审核");
                    document.location.reload();
                }
            }
        });
            return false;
        }, function(){
            layer.msg('您已取消该操作！', {
                time: 2000, //3s后自动关闭
                // btn: ['明白', '知道']
            });
            // document.location.reload();
        });

    })

	//查询
	$(".search_btn").click(function(){
		var querystr = $("#search_input").val();
		location.href = '/actVerf?querystr=' + querystr;
		layer.msg('查询中，请稍候');
		return;
	})


})